﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="~/Content/css/wxcoupon.css?v=1" rel="stylesheet" />
<style>
    .fileinput-button {
        position: absolute;
        display: inline-block;
        overflow: hidden;
    }

        .fileinput-button input {
            position: absolute;
            right: 0px;
            top: 0px;
            opacity: 0;
            -ms-filter: 'alpha(opacity=0)';
            font-size: 200px;
            width: 100%;
            height: 100%;
        }

    .imgItem {
        display: inline-block;
        width: 240px;
    }

    .mini-checkbox label {
        text-align: left;
    }
</style>
<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
    <table style="width: 100%;">
        <tr>
            <td style="width: 100%;">
                <a class="mini-button" name="SaveInfo" iconcls="icon-save" onclick="saveSendFull" plain="true">保存</a>
                <span class="separator"></span>
                <a class="mini-button" id="close" name="close" iconcls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>
</div>
<form id="form1">
    <div class="items">
        <div class="item">
            <label>名称：</label>
            <input type="text" id="FName" name="FName" class="mini-textbox" required="true" vtype="rangeChar:1,18" errormode="none" onvalidation="updateError"
                requirederrortext="名称不能为空" width="230px" />
            <span id="FName_error" class="errorText"></span>
        </div>
        @*     <div class="item">
            <label>开始时间：</label>
            <input type="text" id="notice" name="notice" class="mini-textbox" maxlength="30" required="true" vtype="rangeChar:1,32" errormode="none" onvalidation="updateError"
                requirederrortext="开始时间不能为空" width="230px" />
            <span id="notice_error" class="errorText"></span>
        </div>
        <div class="item">
            <label>结束时间：</label>
            <textarea type="text" id="prerogative" name="prerogative" class="mini-textarea" required="true" vtype="rangeChar:1,2048" errormode="none" onvalidation="updateError"
                requirederrortext="结束时间不能为空" width="230px" height="80px"></textarea>
            <span id="prerogative_error" class="errorText"></span>
        </div>*@
        <div class="item">
            <label>开始时间：</label>
            <input id="FStartDate" name="FStartDate" class="mini-datepicker" format="yyyy-MM-dd H:mm:ss" timeformat="H:mm:ss" showtime="true" required="true" width="230px"
                errormode="none" onvalidation="updateError" requirederrortext="开始时间不能为空" />
            <span id="FStartDate_error" class="errorText"></span>
        </div>
        <div class="item">
            <label>结束时间：</label>
            <input id="FEndDate" name="FEndDate" class="mini-datepicker" format="yyyy-MM-dd H:mm:ss" timeformat="H:mm:ss" showtime="true" required="true" width="230px"
                errormode="none" onvalidation="updateError" requirederrortext="结束时间不能为空" />
            <span id="FEndDate_error" class="errorText"></span>
        </div>
        <div class="item">
            <label>满送金额：</label>
            <input type="text" id="FFullAmount" name="FFullAmount" class="mini-textbox" required="true" errormode="none" onvalidation="updateError"
                requirederrortext="满送金额不能为空" width="230px" />
            <span id="FFullAmount_error" class="errorText"></span>
        </div>
        <div class="item">
            <label>优惠券：</label>
            <div style="display: inline-block; vertical-align: middle;">
                <table>
                    <tr>
                        <td width="70px">
                            <input id="FCouponID" name="FCouponID" class="mini-buttonedit" style="width: 70px;"
                                onbuttonclick="getCouponItem()" onvaluechanged="getCouponValue" selectonfocus="true" />
                        </td>
                        <td width="122px">
                            <input id="FCouponName" name="FCouponName" class="mini-textbox" style="width: 122px; background-color: #CCCCCC;"
                                enabled="false" align="left" readonly="readonly" />
                        </td>
                    </tr>
                </table>
            </div>
            <span id="quantity_error" class="errorText"></span>
        </div>
        <div class="item">
            <label>适用门店：</label>
            <div style="display: inline-block; vertical-align: middle;">@Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")</div>
            <span>不选门店则全部店适用</span>
        </div>
        <div class="item">
            <label>是否启用：</label>
            <div id="FIsEnabled" name="FIsEnabled" class="mini-checkbox" readonly="false" text="启用"></div>
        </div>

    </div>
    <input type="text" id="FItemID" name="FItemID" value="0" class="mini-hidden" />
</form>
<script src="~/Scripts/common.js"></script>
<script>

    function SetInfoData(data) {
        if (data.action == "new") {

        } else {
            var param = {
                FItemID:data.FItemID
            }
            postRequest("/Coupon/GetSendFullInfo", param, function (res) {
                if (res.status == 1) {

                    mini.get("FItemID").setValue(res.data[0].FItemID);
                    mini.get("FName").setValue(res.data[0].FName);
                    mini.get("FStartDate").setText(res.data[0].FStartDate);
                    mini.get("FEndDate").setText(res.data[0].FEndDate);
                    mini.get("FStartDate").setValue(res.data[0].FStartDate);
                    mini.get("FEndDate").setValue(res.data[0].FEndDate);
                    mini.get("FIsEnabled").setValue(res.data[0].FIsEnabled == 1);
                    mini.get("FFullAmount").setValue(res.data[0].FFullAmount);
                    mini.get("FCouponID").setValue(res.data[0].FCouponID);
                    mini.get("FCouponID").setValue(res.data[0].FCouponID);
                    mini.get("FCouponID").setText(res.data[0].FCouponNumber);
                    mini.get("FCouponName").setValue(res.data[0].FCouponName);
                    mini.get("FStockID").getValue(res.data[0].FStockID);
                    mini.get("FStockID").setText(res.data[0].FStockNumber);
                    mini.get("FStockName").setValue(res.data[0].FStockName);
                }
            });
        }
    }

    function CloseWindow(action) {
        if (window.CloseOwnerWindow) window.CloseOwnerWindow(action);
        else window.close();
    }

    function updateError(e) {
        var id = e.sender.name + "_error";
        var el = document.getElementById(id);
        if (el) {
            el.innerHTML = e.errorText;
        }
    }

    function getCouponItem() {
        mini.open({
            url: "/Coupon/CouponItem",
            title: "优惠券选择", width: 730, height: 460,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new" };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if (action.length > 0) {
                    mini.get("FCouponID").setValue(action[0].FItemID);
                    mini.get("FCouponID").setText(action[0].FNumber);
                    mini.get("FCouponName").setValue(action[0].FName);
                }
                else {
                    mini.get("FCouponID").setValue('');
                    mini.get("FCouponID").setText('');
                    mini.get("FCouponName").setValue('');
                }
            }
        });
    }

    function saveSendFull() {
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false)
            return;
        var param = {
            FItemID: mini.get("FItemID").getValue(),
            mSystemAppID: parent.window.getSystemAppID(),
            FName: mini.get("FName").getValue(),
            FStartDate: mini.get("FStartDate").getText(),
            FEndDate: mini.get("FEndDate").getText(),
            FIsEnabled: mini.get("FIsEnabled").checked ? 1 : 0,
            FFullAmount: mini.get("FFullAmount").getValue(),
            FCouponID: mini.get("FCouponID").getValue(),
            FStockID: mini.get("FStockID").getValue()
        }
        postRequest("/Coupon/SaveSendFullInfo", param, function (res) {
            if (res.status == 1) {
                mini.showTips({ content: res.msg, state: "success", x: "center", y: "top", timeout: 3000 });
            } else {
                mini.showTips({ content: res.msg, state: "danger", x: "center", y: "top", timeout: 3000 });
            }
        });
    }
</script>
